import { graphqlKoa, graphiqlKoa } from 'graphql-server-koa'
import { fetchInfo, createInfo } from '../controllers/info'
import schema from '../graphql/schema'

const router = require('koa-router')()

router.post('/fetchInfo', fetchInfo)
      .post('/createInfo', createInfo)

router.post('/graphql', async (ctx, next) => {
        await graphqlKoa({schema: schema})(ctx, next)
      })
      .get('/graphql', async (ctx, next) => {
        await graphqlKoa({schema: schema})(ctx, next)
      })
      .get('/graphiql', async (ctx, next) => {
        await graphiqlKoa({endpointURL: '/graphql'})(ctx, next)
      })

module.exports = router
